/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sengoku2;

import javax.swing.JOptionPane;

/**
 *
 * @author Ronald
 */
public class Board {

    int side = 12;
    Piece[][] spaces = new Piece[12][12];

    public Board() {
        for (int row = 00; row < side; row++) {
            for (int column = 0; column < side; column++) {
                spaces[row][column] = new Piece();
            }
        }
    }

    public void MakePieces() {
        Piece uplowBravo = new Piece(" [b] "," [b] ", 2, 4, false, true, false);
        Piece uplowGamma = new Piece(" [g] "," [g] ", 2, 5, false, true, false);
        Piece uplowDelta = new Piece(" [d] "," [d] ", 3, 4, false, true, false);
        Piece lowupBravo = new Piece(" [B] "," [B] ", 0, 0, true, true, false);
        Piece lowupGamma = new Piece(" [G] "," [G] ", 0, 0, true, true, false);
        Piece lowupDelta = new Piece(" [D] "," [D] ", 9, 5, true, true, false);
        Piece upleftSierra = new Piece(" [S] "," [S] ", 5, 1, true, true, false);
        Piece upleftUni = new Piece(" [U] ", " [U] ", 5, 2, true, true, false);
        Piece upleftTango = new Piece(" [T] "," [T] ", 6, 2, true, true, false);
        Piece lowrightSierra = new Piece(" [s] "," [s] ", 0, 0, false, true, false);
        Piece lowrightUni = new Piece(" [u] "," [u] ", 0, 0, false, true, false);
        Piece lowrightTango = new Piece(" [t] "," [t] ", 0, 0, false, true, false);
        spaces[2][4] = uplowBravo;
        spaces[2][5] = uplowGamma;
        spaces[2][6] = uplowGamma;
        spaces[2][7] = uplowBravo;
        spaces[3][4] = uplowDelta;
        spaces[3][5] = uplowDelta;
        spaces[3][6] = uplowDelta;
        spaces[3][7] = uplowDelta;
        spaces[5][1] = upleftSierra;
        spaces[6][1] = upleftUni;
        spaces[7][1] = upleftUni;
        spaces[8][1] = upleftSierra;
        spaces[5][2] = upleftTango;
        spaces[6][2] = upleftTango;
        spaces[7][2] = upleftTango;
        spaces[8][2] = upleftTango;
        spaces[9][4] = lowupDelta;
    }

    public void MakeBoard() {
        String space = "    ";
        for (int index = 0; index < side; index++) {
            space += index + "    ";
        }
        space += "\n";
        for (int row = 00; row < side; row++) {
            if (row > 9) {
                space += row;
            } else {
            space += row + " ";
            }
            for (int column = 0; column < side; column++) {
                space += spaces[row][column].name;
            }
            space += "\n";
        }
        System.out.println(space);
    }

    public void Play() {
        while (1 > 0) {
            String r = JOptionPane.showInputDialog("What row? ");
            int row = Integer.parseInt(r);
            String c = JOptionPane.showInputDialog("What column? ");
            int column = Integer.parseInt(c);
            if (spaces[row][column].isUpperCase) {
                if (spaces[row][column].isAlpha) {
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either up, down, left, or right: ");
                        String move = m;
                        if (move.equalsIgnoreCase("up")) {
                            spaces[row + 1][column].getStateA();
                        } else if (move.equalsIgnoreCase("down")) {
                            spaces[row - 1][column].getStateA();
                        } else if (move.equalsIgnoreCase("left")) {
                            spaces[row][column - 1].getStateA();
                        } else if (move.equalsIgnoreCase("right")) {
                            spaces[row][column + 1].getStateA();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                } else {
                    // stuff for beta pieces
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either forright, forleft, backleft, or backright: ");
                        String move = m;
                        if (move.equalsIgnoreCase("forright")) {
                            spaces[row + 1][column + 1].getStateB();
                        } else if (move.equalsIgnoreCase("forleft")) {
                            spaces[row + 1][column - 1].getStateB();
                        } else if (move.equalsIgnoreCase("backleft")) {
                            spaces[row - 1][column - 1].getStateB();
                        } else if (move.equalsIgnoreCase("backright")) {
                            spaces[row - 1][column + 1].getStateB();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                }
            } else {
                if (spaces[row][column].isAlpha) {
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either up, down, left, or right: ");
                        String move = m;
                        if (move.equalsIgnoreCase("up")) {
                            spaces[row + 1][column].getStateLA();
                        } else if (move.equalsIgnoreCase("down")) {
                            spaces[row - 1][column].getStateLA();
                        } else if (move.equalsIgnoreCase("left")) {
                            spaces[row][column - 1].getStateLA();
                        } else if (move.equalsIgnoreCase("right")) {
                            spaces[row][column + 1].getStateLA();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                } else {
                    // stuff for beta pieces
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either forright, forleft, backleft, or backright: ");
                        String move = m;
                        if (move.equalsIgnoreCase("forright")) {
                            spaces[row + 1][column + 1].getStateLB();
                        } else if (move.equalsIgnoreCase("forleft")) {
                            spaces[row + 1][column - 1].getStateLB();
                        } else if (move.equalsIgnoreCase("backleft")) {
                            spaces[row - 1][column - 1].getStateLB();
                        } else if (move.equalsIgnoreCase("backright")) {
                            spaces[row - 1][column + 1].getStateLB();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                }
            }
        }
    }
}
